import { SEARCH_SET_VALUE, SEARCH_CLEAR_VALUE } from '../mutation-types';

const state = {
  value: '',
  data: {},
  willSearch: false
};

const getters = {
  value: (state) => state.value,
  willSearch: (state) => state.willSearch
};

const mutations = {
  [SEARCH_SET_VALUE](state, payload) {
    state.value = payload.value;
    state.willSearch = true;
  },
  [SEARCH_CLEAR_VALUE](state) {
    state.willSearch = false;
  }
};

const actions = {
  [SEARCH_SET_VALUE]({ commit }, value) {
    commit({
      type: SEARCH_SET_VALUE,
      value: value
    });
  },
  [SEARCH_CLEAR_VALUE]({ commit }) {
    commit({
      type: SEARCH_CLEAR_VALUE
    });
  }
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
};
